/*
 * @Author: Zcl84765
 * @Date: 2020-04-09 18:12:36
 * @LastEditors: Zcl84765
 * @LastEditTime: 2023-02-06 17:44:43
 */
import { json } from 'body-parser'
import Vue from 'vue'
import Vuex from 'vuex'

import uInfo from './module/users'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    rightList: JSON.parse(sessionStorage.getItem('rightList') || '[]'),
    userInfo: JSON.parse(sessionStorage.getItem('userInfo') || '{}'),
    token: JSON.parse(sessionStorage.getItem('token')) || '',
    num: 1,
    tokenStr: JSON.parse(sessionStorage.getItem('tokenStr')) || '',
    name: '',
  },
  mutations: {
    stateChange(state, Num) {
      state.num = Num
      localStorage.setItem('num', Num)
    },
    nameChanage(state,data) {
      state.name = data
    },
    setRightList(state, data) {
      state.rightList = data
      sessionStorage.setItem('rightList', JSON.stringify(data)) // 将权限数据保存在本地   持久化
    },
    setUserInfo(state, data) {
      state.userInfo = data
      sessionStorage.setItem('userInfo', JSON.stringify(data)) //保存用户数据
    },
    setToken(state, data) {
      state.token = data
      sessionStorage.setItem('token', JSON.stringify(data)) //保存用户数据
    },
    setTokenStr(state, data) {
      state.tokenStr = data
      sessionStorage.setItem('tokenStr', JSON.stringify(data))
    },
  },
  actions: {
    getNewNum(context, num) {
      console.log(context)
      // 同上注释，num为要变化的形参
      context.commit('stateChange', num)
    },
  },
  getters: {},
  modules: {
    uInfo,
  },
})
